package com.itheima.exer.exercise.ex0924;

import java.math.BigDecimal;

/**
 * 今日案例[API]:定义一个String字符串,内容为:91.4 27.23 46.4 38.7 50.2,
 * 求这个字符串中数字的平均值
 * /二分查找/冒泡排序/递归求阶乘
 */
public class Demo1 {
    public static void main(String[] args) {
        String str = "91.4 27.23 46.4 38.7 50.2";
        String[] split = str.split(" ");
        //BigDecimal bigDecimal1 = new BigDecimal(split[0]);
        BigDecimal bigDecimal2 = BigDecimal.ZERO;
        for (int i = 0; i < split.length; i++) {
            BigDecimal bigDecimal3 = new BigDecimal(split[i]);
            bigDecimal2 = bigDecimal2.add(bigDecimal3);

        }
        BigDecimal bigDecimal4 = new BigDecimal(split.length);
        BigDecimal divide = bigDecimal2.divide(bigDecimal4, 2, BigDecimal.ROUND_HALF_UP);
        System.out.println(divide);
    }
}
